export type OAuthConfig = {
    clientId: string;
    clientSecret: string;
    redirectUri: string;
    scopes: string[];
    authUrl?: string;
    tokenUrl?: string;
    userInfoUrl?: string;
}

class BaseOAuthProvider {

    clientId: string;
    clientSecret: string;
    redirectUri: string;
    scopes: string[];
    authUrl?: string;
    tokenUrl?: string;
    userInfoUrl?: string;

    constructor(config: OAuthConfig) {
        this.clientId = config.clientId;
        this.clientSecret = config.clientSecret;
        this.redirectUri = config.redirectUri;
        this.scopes = config.scopes;
        this.authUrl = config.authUrl;
        this.tokenUrl = config.tokenUrl;
        this.userInfoUrl = config.userInfoUrl;
    }

    generateAuthUrl(state?: string) {
        const params = new URLSearchParams({
            client_id: this.clientId,
            redirect_uri: this.redirectUri,
            response_type: 'code',
            scope: this.scopes.join(' '),
            state: state || 'default_state',
        });

        return `${this.authUrl}?${params.toString()}`;
    }

    async exchangeCodeForTokens(code: string, state?: string) {
        throw new Error('exchangeCodeForTokens must be implemented');
    }

    async getUserInfo(accessToken: string) {
        throw new Error('getUserInfo must be implemented');
    }

    processUserData(userInfo: any) {
        throw new Error('processUserData must be implemented');
    }
}

export default BaseOAuthProvider;